package rubik.crossover;

import rubik.CubeSolution;
import rubik.ICubeSolution;

public class CogwheelCrossOver extends AbstractCrossOver{

	@Override
	public ICubeSolution applyCrossOver(ICubeSolution firstParent,
			ICubeSolution secondParent) {
		
		CubeSolution newSeq = new CubeSolution(firstParent.getCube(), firstParent.getSeqGenerator(), firstParent.getMutator(), firstParent.getFitnessFunc(), firstParent.getCrossoverFunc());
		ICubeSolution longestSequence = firstParent.getSeqs().size() > secondParent.getSeqs().size() ? firstParent : secondParent;
		int counter = 0;
		
		for (int i = 0; i < Math.min(firstParent.getSeqs().size(), secondParent.getSeqs().size()); i++) {
			if ((i % 2) == 0 ){
				newSeq.getSeqs().add(firstParent.getSeqs().get(i));
			}
			else {
				newSeq.getSeqs().add(secondParent.getSeqs().get(i));
			}
			counter++;
		}
		for (int i = counter; i < longestSequence.getSeqs().size(); i++){
			newSeq.getSeqs().add(longestSequence.getSeqs().get(i));
		}
		
	return newSeq;
	
	}
	
	

}
